const path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
//const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    entry: { index: './index.js' },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name]-[contenthash].js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                    }
                }
            },
            {
                test: /\.less$/,
                use: [{
                    loader: "style-loader" // 将 JS 字符串生成为 style 节点
                }, {
                    loader: "css-loader" // 将 CSS 转化成 CommonJS 模块
                }, {
                    loader: "less-loader" 
                }]
            },
            {
                test: /\.css$/,
                use: [{
                    loader: "style-loader" // 将 JS 字符串生成为 style 节点
                }, {
                    loader: "css-loader" // 将 CSS 转化成 CommonJS 模块
                }]
            },
            {
                test: /\.(png|jpg)$/,
                use: {
                    loader: 'file-loader'
                }
            },
            {
                test: /\.html$/,
                use: {
                    loader: 'raw-loader'
                }
            }
        ]
    },
    devServer: {
        //contentBase: './dist',
        compress: false,
        port: 30001,
        proxy: {
            '/api': {
              target: 'http://localhost:30000',
              pathRewrite: {
                '^/api': '' // 替换掉代理地址中的 /api
              }
            }
          }
    },
    devtool: 'source-map',
    plugins: [
        new HtmlWebpackPlugin({ title: '接口文档' }),
        // new CopyWebpackPlugin({patterns:[{
        //     from: './target', to: path.resolve(__dirname, 'dist/target')
        // }]})
    ]
};
